﻿/*
 * Author:xmfdsh 11届网络部--邓世豪
 * DataTime：2014-6-9
 * Copyright © 2014 大学生勤工助学服务队 Powered by xmfdsh & 四小狼工作室.
 * 版权所有，违者必究
 */
using QGZX.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace QGZX.Logic.QGOA
{
    public class BaseInfoController : Controller
    {
        #region  个人用户信息页面 + ActionResult Info()
        /// <summary>
        /// 个人用户信息页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Info()
        {
            MODEL.qgzx_config model = OperateContext.Current.BLLSession.Iqgzx_configBLL.GetListBy(x => x.SystemName != null).FirstOrDefault();
            ViewBag.configModel = model;
            //从session取到user
            MODEL.qgoa_user user = (MODEL.qgoa_user)Session["user"];
            ViewBag.user = user;
            return View();
        } 
        #endregion

        #region Action处理方法集合 + ActionResult Action()
        /// <summary>
        /// Action处理方法集合
        /// </summary>
        /// <returns></returns>
        public ActionResult Action()
        {
            string dowhat = Request.Form["dowhat"];
            // 身份验证
            if (Session["user"] == null)
            {
                Response.Write("未登录或登录超时");
                return null;
            }
            MODEL.qgoa_user user = new MODEL.qgoa_user();
            user = (MODEL.qgoa_user)Session["user"];

            if (dowhat.Equals("update_base_info"))
            {
                string Id = user.Id.ToString();

                string Avatar = Request.Form["Avatar"];
                string Name = Request.Form["Name"];
                string Sexual = Request.Form["Sexual"];
                string BirthPlace = Request.Form["BirthPlace"];
                string BirthDay = Request.Form["BirthDay"];
                string IdNumber = Request.Form["IdNumber"];
                string CellPhone = Request.Form["CellPhone"];
                string QQ = Request.Form["QQ"];
                string Weibo = Request.Form["Weibo"];
                string Email = Request.Form["Email"];
                string Major = Request.Form["Major"];
                string RealPassword = Request.Form["RealPassword"];

                string BaseInfoFormatString = "{{\"Avatar\":\"{0}\",\"Name\":\"{1}\",\"Sexual\":\"{2}\",\"BirthPlace\":\"{3}\",\"BirthDay\":\"{4}\",\"IdNumber\":\"{5}\",\"CellPhone\":\"{6}\",\"QQ\":\"{7}\",\"Weibo\":\"{8}\",\"Email\":\"{9}\",\"Major\":\"{10}\"}}";
                string BaseInfo = string.Format(BaseInfoFormatString, Avatar, Name, Sexual, BirthPlace, BirthDay, IdNumber, CellPhone, QQ, Weibo, Email, Major);

                MODEL.qgoa_user u = new MODEL.qgoa_user() { Id = Convert.ToInt32(Id), BaseInfo = BaseInfo, RealPassword = RealPassword };


                if (OperateContext.Current.BLLSession.Iqgoa_userBLL.Modify(u, "BaseInfo", "RealPassword") > 0)
                {
                    return OperateContext.Current.RedirectAjax("or", "操作成功", null, "");
                }
                else
                {
                    return OperateContext.Current.RedirectAjax("err", "操作失败", null, "");
                }
                return OperateContext.Current.RedirectAjax("err", "操作失败", null, "");
            }
            return OperateContext.Current.RedirectAjax("err", "操作失败", null, "");
        } 
        #endregion
    }
}
